package com.handpay.nocardpay.baselibrary.main.home.presenter;

import android.content.Context;

import com.handpay.nocardpay.baselibrary.commbase.model.IBaseModel;
import com.handpay.nocardpay.baselibrary.commbase.model.bean.BaseErrorInfo;
import com.handpay.nocardpay.baselibrary.commbase.presenter.IBasePresenter;
import com.handpay.nocardpay.baselibrary.main.home.model.PaymentTypeListModelImpl;
import com.handpay.nocardpay.baselibrary.main.home.model.bean.PaymentTypeListBean;
import com.handpay.nocardpay.baselibrary.main.home.view.IHomeView;

import java.util.HashMap;

/**
 * Created by lyang on 2017/9/22.
 */

public class PaymentTypeListPresenter implements IBasePresenter, IBaseModel.OnRequestFinishedListener<PaymentTypeListBean>{

    private PaymentTypeListModelImpl mPaymentTypeListModelImpl;
    private IHomeView mHomeView;
    private Context mContext;

    public PaymentTypeListPresenter(IHomeView homeView, Context context) {
        this.mPaymentTypeListModelImpl = new PaymentTypeListModelImpl(context);
        this.mHomeView = homeView;
        this.mContext = context;
    }


    /**
     * 获取可用支付类型列表
     *
     * @param paramers
     * @param clzz
     * @param isShowLoading
     */
    public void getPaymentTypeList(HashMap<String, Object> paramers, Class<PaymentTypeListBean> clzz, boolean isShowLoading) {
        if (mHomeView != null) {
            if (isShowLoading) {
                mHomeView.showProgress();
            }
        }
        mPaymentTypeListModelImpl.request(paramers, clzz, this);
    }

    @Override
    public void onError(BaseErrorInfo baseErrorInfo) {
        if (mHomeView != null) {
            mHomeView.hideProgress();
            mHomeView.showErrorAlert(baseErrorInfo);
        }
    }

    @Override
    public void onSuccess(PaymentTypeListBean response) {
        if (mHomeView != null) {
            mHomeView.hideProgress();
            mHomeView.setPaymentTypeList(response);
        }
    }

    @Override
    public void onDestory() {

    }
}
